#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>

void scan(int & a)
{
	a = 0;
	bool flag = false;
	char ch = std::getchar();
	if (ch == '-')
		flag = true;
	else if (ch >= '0' && ch <= '9')
		a = ch - '0';

	while ((ch = std::getchar()) >= '0' && ch <= '9')
		a = a * 10 + ch - '0';
	if (flag) a = -a;
}

struct data { int x, y, z; };
struct pair { int x, v; };

bool cmp1(pair const& a, pair const& b) { return a.x < b.x || (a.x == b.x && a.v > b.v); }
bool cmp2(pair const& a, pair const& b) { return a.x > b.x || (a.x == b.x && a.v > b.v); }

int const maxn = 20007;
data left[maxn], right[maxn];
std::set<int> dis;
int DIS[maxn];
int ls[maxn];
int rs[maxn];
pair v[maxn];
int tl, tr, n, size, len;

void init() { dis.clear(); tl = tr = 0; }
bool out_range(data const& a) { return a.y - a.x > 2 * a.z; }

int main()
{
	int T; scan(T);
	for (int cas = 1; cas <= T; cas++) {
		printf("Case #%d:\n", cas);
		init();
		data input;
		scan(n);
		for (int i = 0, d; i < n; i++) {
			scan(input.x);
			scan(input.y);
			scan(input.z);
			scan(d);
			if (out_range(input)) continue;
			if (d == -1) left[tl++] = input;
			else right[tr++] = input;
			dis.insert(input.y - input.z);
			dis.insert(input.x + input.z);
		}
		len = size = 0;
		for (std::set<int>::iterator it = dis.begin(); it != dis.end(); ++it) DIS[size++] = *it;
		for (int i = 0; i < tl; i++) {
			pair tmp;
			tmp.x = left[i].y - left[i].z;
			tmp.v = 1;
			v[len++] = tmp;
			tmp.x = left[i].x + left[i].z;
			tmp.v = -1;
			v[len++] = tmp;
		}
		std::sort(v, v + len, cmp1);
		int sum = 0, t = 0, tot = 0;
		for (int it = 0; it < size; it++) {
			while (t < len && v[t].x <= DIS[it] && v[t].v > 0) sum += v[t++].v;
			ls[tot++] = sum;
			while (t < len && v[t].x <= DIS[it]) sum += v[t++].v;
		}
		len = 0;
		for (int i = 0; i < tr; i++) {
			pair tmp;
			tmp.x = right[i].y - right[i].z;
			tmp.v = -1;
			v[len++] = tmp;
			tmp.x = right[i].x + right[i].z;
			tmp.v = +1;
			v[len++] = tmp;
		}
		std::sort(v, v + len, cmp2);
		sum = t = tot = 0;
		for (int it = size - 1; it >= 0; it--) {
			while (t < len && v[t].x >= DIS[it] && v[t].v > 0)
				sum += v[t++].v;
			rs[size - (++tot)] = sum;
			while (t < len && v[t].x >= DIS[it])
				sum += v[t++].v;
		}
		int max = 0, ans = 0;
		tot = 0;
		for (std::set<int>::iterator it = dis.begin(); it != dis.end(); ++it) {
			max = std::max(max, rs[tot]);
			ans = std::max(ans, ls[tot++] + max);
		}
		printf("%d\n", ans);
	}
}

